<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '评论管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                'attribute' => 'id',
                'contentOptions' => ['width' => '30px', 'align' => 'center'],
            ],
            //'content:ntext',
            [
                'attribute' => 'content',
                /*'value' => function ($model)
                {
                    $tmpStr = strip_tags($model->content);
                    $tmLen = mb_strlen($tmpStr);
                    return mb_substr($tmpStr, 0, 10). ( $tmLen > 10 ? '...':'');
                }*/
                'value' => 'beginning',
            ],
            //'status',
            [
                'attribute' =>  'status',
                'label' =>  '状态',
                'value' => 'status0.name',
                //'filter' => \common\models\Commentstatus::find()->select(['name','id'])->orderBy('position')->indexBy('id')->column(),
                'filter' => $searchModel->columnName,
                'contentOptions' => function ($model)
                {
                    return ($model->status == 1) ? ['class' => 'bg-danger'] : [];
                }
            ],
            //'userid',
            [
                'attribute'  => 'user.username',
                'label'  =>  '昵称',
                'value' => 'user.username'
            ],
            // 'post_id',
            'post.title',
            //'create_time:datetime',
            [
                'attribute' =>  'create_time',
                'value' => function ($model)
                {
                    return date('Y-m-d H:i:s', $model->create_time);
                }
            ],
            // 'email:email',
            // 'url:url',

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view},{update},{delete},{approve}',
                'buttons' => [
                    'approve' => function ($url, $model, $key)
                    {
                        $options = [
                            'title' => Yii::t('yii', '审核'),
                            'aria-lable' => Yii::t('yii', '审核'),
                            'data-confirm' => Yii::t('yii', '你确定要审核通过这条评论吗?'),
                            'data-method' => 'post',
                            'data-pjax' => '0',
                        ];
                        $icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-check"]);
                        //$icon = '<span class="glyphicon glyphicon-check"></span>>';
                        return Html::a($icon, $url, $options);
                    }
                ],
            ],
        ],
    ]); ?>
</div>
